package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleService;
import com.heima.model.common.dtos.app.ArticleDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component("ArticleListener")
public class ArticleListener {
    @Autowired
    private ApArticleService apArticleService;
    @KafkaListener(topics = "article-Topic")
    public void listen(String message) {
        if(message!=null){
            ArticleDto articleDto = JSON.parseObject(message, ArticleDto.class);
            apArticleService.saveArticle(articleDto);
        }
    }
}
